//
//  SelectProductCell.m
//  FactorySale
//
//  Created by 主事丫环HU on 2020/7/27.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "SelectProductCell.h"
#import "SYBigImage.h"
@interface SelectProductCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contractPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *salePriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *isPostLabel;
@property (weak, nonatomic) IBOutlet UILabel *isNotPostLabel;

@end
@implementation SelectProductCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)cellWithTableView:(UITableView *)tableView {
    
    static NSString *ID = @"SelectProductCell";
    
    SelectProductCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [NSBundle.mainBundle loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)setModel:(SelectProductListModel *)model{
    
    self.selectOneButton.selected = model.isSelected;
    
    self.nameLabel.text = model.attributeName;
    self.contractPriceLabel.text = [NSString stringWithFormat:@"合同价:¥%.2f/%@",model.contractPrice,model.unit];
    self.salePriceLabel.text = [NSString stringWithFormat:@"售价:¥%.2f/%@",model.price,model.unit];
    if ([model.isPost isEqualToString:@"0"]) {
        self.isPostLabel.hidden = YES;
        self.isNotPostLabel.hidden = NO;
    } else {
        self.isPostLabel.hidden = NO;
        self.isNotPostLabel.hidden = YES;
    }
    
    __weak typeof(self) _weakSelf = self;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.attributeLogo] placeholderImage:imgname(GOODS_PLACE_HOLDER) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image && cacheType == SDImageCacheTypeNone) {
            _weakSelf.iconImageView.alpha = 0;
            [UIView animateWithDuration:1.0 animations:^{
                _weakSelf.iconImageView.alpha = 1.0f;
            }];
        } else {
            _weakSelf.iconImageView.alpha = 1.0f;
        }
    }];
    SYBigImage * bigI = [[SYBigImage alloc]init];
    [self.iconImageView addGestureRecognizer:bigI];
    self.iconImageView.userInteractionEnabled = YES;

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
